<template>
  <div class="risk-statistics">
    <span class="title">风险统计</span>
    <span class="vice-title">近一周预警统计</span>
    <div class="content">
      <el-row style="width:100%"
              type="flex"
              justify="space-between">
        <el-col :span="6">
          <div class="all">
            <div class="title">总预警</div>
            <div>
              <div class="bg">
                <div class="num">{{totalAlert}}</div>
                <div class="tips">预警总台数</div>
              </div>
            </div>

          </div>
        </el-col>
        <el-col :span="6">
          <div class="alert_num">
            <div class="title">预警台数</div>
            <div class="detail">
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/num_tem.png')"></el-image>
                  <span>温度</span>
                </div>
                <div class="num">{{alertNum.TEMPERATURE}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image cla
                            :src="require('@/assets/platformDetail/num_water.png')"></el-image>
                  <span>湿度</span>
                </div>
                <div class="num">{{alertNum.HUMIDITY}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/num_co2.png')"></el-image>
                  <span>CO2</span>
                </div>
                <div class="num">{{alertNum.CO2}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/num_pm25.png')"></el-image>
                  <span>PM2.5</span>
                </div>
                <div class="num">{{alertNum.PM25}}</div>
              </el-row>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="alert_time">
            <div class="title">
              预警时长
              <span class="unit">(h)</span>
            </div>
            <div class="detail">
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/time_tem.png')"></el-image>
                  <span>温度</span>
                </div>
                <div class="num">{{alertTime.TEMPERATURE}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/time_water.png')"></el-image>
                  <span>湿度</span>
                </div>
                <div class="num">{{alertTime.HUMIDITY}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/time_co2.png')"></el-image>
                  <span>CO2</span>
                </div>
                <div class="num">{{alertTime.CO2}}</div>
              </el-row>
              <el-row type="flex"
                      justify="space-between">
                <div class="left_flex">
                  <el-image class="el-image"
                            :src="require('@/assets/platformDetail/time_pm25.png')"></el-image>
                  <span>PM2.5</span>
                </div>
                <div class="num">{{alertTime.PM25}}</div>
              </el-row>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getStatisticWeek } from "@/api/platformManage";
export default {
  name: "riskStatistics",
  components: {},
  props: {
    platformId: String
  },
  data() {
    return {
      alertNum: {
        TEMPERATURE: 0,
        HUMIDITY: 0,
        CO2: 0,
        PM25: 0
      },
      alertTime: {
        TEMPERATURE: 0,
        HUMIDITY: 0,
        CO2: 0,
        PM25: 0
      },
      totalAlert: 0
    };
  },
  watch: {
    platformId() {
      this.getAlertNumFun();
    }
  },
  mounted() {
  },
  methods: {
    //获取平台预警数量
    getAlertNumFun() {
      getStatisticWeek(this.platformId).then(res => {
        this.totalAlert = res.value.totalAlertDeviceNum;
        let data = res.value.dataTypeEvaluateStatistics;
        for (let i = 0; i < data.length; i++) {
          this.alertNum[data[i].type] = data[i].alertDeviceNum;
          let durationSeconds = data[i].alertDurationSeconds / 3600;
          if (durationSeconds == 0) {
            this.alertTime[data[i].type] = durationSeconds;
          } else if (durationSeconds > 999) {
            this.alertTime[data[i].type] = durationSeconds.toFixed(0);
          } else {
            this.alertTime[data[i].type] = durationSeconds.toFixed(1);
          }
        }
        // let keys = Object.values(this.alertNum);
        // console.log("****", keys);

        // for (let i = 0; i < keys.length; i++) {
        //   this.totalAlert += keys[i];
        // }
      });
    }
  }
};
</script>
<style scoped lang="scss">
.risk-statistics {
  background-color: #fff;
  border-radius: 12px;
  padding: 20px;
  .title {
    font-size: 16px;
    font-weight: bold;
    line-height: 21px;
    color: #0a0a0a;
  }
  .vice-title {
    font-size: 14px;
    font-weight: 400;
    line-height: 21px;
    color: #707070;
    margin-left: 10px;
  }
  .content {
    display: flex;
    align-items: center;
    .text {
      font-size: 16px;
      font-weight: 400;
      line-height: 21px;
      color: #535353;
      margin-right: 20px;
    }
    .all {
      .title {
        font-size: 16px;
        font-weight: 400;
        line-height: 40px;
        text-align: center;
        color: #0d0c0c;
        border-bottom: 2px solid #fc360d;
      }
      .num {
        width: 70%;
        margin: auto;
        background-image: url("../../../../../assets/platformDetail/all_bg.png");
        background-position: center;
        background-size: 100% 100%;
        font-size: 44px;
        font-weight: bold;
        line-height: 105px;
        color: #fc360d;
        text-align: center;
      }
      .tips {
        font-size: 14px;
        font-weight: 400;
        line-height: 19px;
        color: #707070;
        text-align: center;
      }
    }
    .alert_num {
      .title {
        border-bottom: 2px solid #3d88f8;
      }
    }
    .alert_time {
      .title {
        border-bottom: 2px solid #f8b61b;
      }
    }
    .alert_num,
    .alert_time {
      .title {
        font-size: 16px;
        font-weight: 400;
        line-height: 40px;
        text-align: center;
        color: #0d0c0c;
        margin-bottom: 10px;
      }
      .detail {
        padding-top: 15px;
        font-size: 14px;
        font-weight: 400;
        line-height: 24px;
        color: #1a1919;
        .num {
          font-size: 20px;
          font-weight: bold;
          line-height: 24px;
          color: #1a1a1a;
        }
        .left_flex {
          display: flex;
          align-items: center;
          vertical-align: middle;
          .el-image {
            margin-right: 5px;
            display: flex;
            width: 12px;
          }
        }
      }
    }
  }
}
@media screen and (max-width: 1670px) {
  .risk-statistics {
    .content {
      display: flex;
      align-items: center;
      .text {
        font-size: 16px;
        font-weight: 400;
        line-height: 21px;
        color: #535353;
        margin-right: 20px;
      }
      .all {
        .num {
          width: 100%;
          margin: auto;
          background-image: url("../../../../../assets/platformDetail/all_bg.png");
          background-position: center;
          background-size: 100% 100%;
          font-size: 34px;
          font-weight: bold;
          line-height: 105px;
          color: #fc360d;
          text-align: center;
        }
        .tips {
          font-size: 14px;
          font-weight: 400;
          line-height: 19px;
          color: #707070;
          text-align: center;
        }
      }
    }
  }
}
</style>
